package com.theeviljames;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;

public class MessageDecoder {

	private static String lines = "wx vjnh,"+
	"hd, xu ndj rpc gtps iwxh, ndj wpkt udjcs iwt udgbjap udg rdcktgixcv "+
	"iwxh rdst id itmi. id vti iwt ctmi ithi tbpxa bt iwt ldgs pcprdcsp "+
	"rpirw j apitg udazh " + 
	"eh: uxghi id pchltg vti p rwdrdapit qpg :)";

	
    //x->i
    //i->t
    //t->e
	public static String process(String text){
		String processed = "";
		for(int i = 0; i < text.length(); i++){
			String current = text.substring(i, i+1);
			if(current.equals("x")){
				processed += "i";
			}
			else if(current.equals("i")){
				processed += "t";
			}
			else if(current.equals("t")){
				processed += "e";
			}
			else if(current.equals("w")){
				processed += "h";
			}
			else if(current.equals("v")){
				processed += "g";
			}
			else if(current.equals("h")){
				processed += "s";
			}
			else if(current.equals("d")){
				processed += "o";
			}
			else if(current.equals("j")){
				processed += "u";
			}
			else if(current.equals("n")){
				processed += "y";
			}
			else if(current.equals("u")){
				processed += "f";
			}
			else if(current.equals("p")){
				processed += "a";
			}
			else if(current.equals("k")){
				processed += "v";
			}
			else if(current.equals("r")){
				processed += "c";
			}
			else if(current.equals("s")){
				processed += "d";
			}
			else if(current.equals("g")){
				processed += "r";
			}
			else if(current.equals("c")){
				processed += "n";
			}
			else if(current.equals("b")){
				processed += "m";
			}
			else if(current.equals("a")){
				processed += "l";
			}
			else if(current.equals("m")){
				processed += "x";
			}
			else if(current.equals("z")){
				processed += "k";
			}
			else if(current.equals("q")){
				processed += "b";
			}
			else if(current.equals("e")){
				processed += "p";
			}
			else if(current.equals("l")){
				processed += "w";
			}
			
			else{
				processed += current;
			}
		}
		return processed;
	}
	
	public static Hashtable<String, Integer> charCount(String text){
		Hashtable<String, Integer> characterCount = new Hashtable<String, Integer>();
		for(int i = 0; i < text.length(); i++){
			String current = text.substring(i, i+1);
			if(characterCount.containsKey(current)){
				int n = characterCount.remove(current);
				n += 1;
				characterCount.put(current, n);
			}
			else{
				characterCount.put(current, 1);
			}
		}
		return characterCount;
	}
	
	public static Hashtable<String, Integer> wordCount(String text){
		Hashtable<String, Integer> wordCount = new Hashtable<String, Integer>();
		StringTokenizer st = new StringTokenizer(text," ,.");
		while(st.hasMoreTokens()){
			String current = st.nextToken();
			if(wordCount.containsKey(current)){
				int n = wordCount.remove(current);
				n += 1;
				wordCount.put(current, n);
			}
			else{
				wordCount.put(current, 1);
			}
		}
		return wordCount;
	}
	
	public static void main(String[] args) {
		System.out.println(lines);
		System.out.println(process(lines));
		Hashtable<String, Integer> characterCount = charCount(lines);
		for(Enumeration<String> e = characterCount.keys(); e.hasMoreElements();){
			String s = e.nextElement();
			System.out.println(s + ">" + characterCount.get(s));
		}
		Hashtable<String, Integer> wordCount = wordCount(lines);
		for(Enumeration<String> e = wordCount.keys(); e.hasMoreElements();){
			String s = e.nextElement();
			if(wordCount.get(s)!=1)System.out.println(s + ">" + wordCount.get(s));
		}
		
	}
}
